package artid.com.arttogo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.AuctionHomeParser;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;

/**
 * 
*    
* 项目名称：ArtworkArt   
* 类名称：CertificationItems_Adapter   
* 类描述：拍卖行-认证拍品适配器   
* 创建人：耿卫斌   
* 创建时间：2017-3-1 下午12:54:32   
*
 */
public class CertificationItems_Adapter extends BaseAdapter {
	private Context mContext;
	private List<AuctionHomeParser.AuctionHomeLotinfo> list;

	public CertificationItems_Adapter(Context mContext, List<AuctionHomeParser.AuctionHomeLotinfo> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_certificationitems, null);
			holder.img=(ImageView) v.findViewById(R.id.itemCertificationItems_img);
			holder.isKeepOnRecord=(ImageView) v.findViewById(R.id.itemCertificationItems_isKeepOnRecord);
			holder.context=(TextView) v.findViewById(R.id.itemCertificationItems_context);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		LayoutParams para= holder.img.getLayoutParams();
		para.width = list.get(position).getWidth();  
		holder.img.setLayoutParams(para); 
		Glide.with(mContext).load(list.get(position).getImgurl()
				+ "_"+ NetUtils.dip2px(mContext, 200)+"x10.png"
				).asBitmap().centerCrop()
		.placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
		.into(new MyBitmapImageViewTarget(holder.img));
		holder.context.setText(list.get(position).getLot_name());
		if("1".equals(list.get(position).getIs_record())){
			//已备案
			holder.isKeepOnRecord.setVisibility(View.VISIBLE);
		}else{
			holder.isKeepOnRecord.setVisibility(View.GONE);
		}
		return v;
	}
	class ViewHolder {
		ImageView img,isKeepOnRecord;
		TextView context;
	}
}
